/*
  Copyright 2011 Frogtek BOP LLC

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.frogtek.database;

import org.frogtek.database.android.AndroidDatabaseConnection;
import org.frogtek.database.interfaces.IDatabaseConnection;

import android.content.Context;
import org.frogtek.database.exceptions.DatabaseConnectionException;
import org.frogtek.database.interfaces.Database;

public class DatabaseConnectionFactory {
    public static final int ANDROID_DATABASE = 1;
    private Context mContext = null;
    public IDatabaseConnection getConnection(Database theDatabase) throws Exception {
        if(theDatabase.getType() == DatabaseConnectionFactory.ANDROID_DATABASE) {
            if(this.mContext==null) {
                throw new DatabaseConnectionException("Android database needs a context");
            }
            return new AndroidDatabaseConnection(this.mContext,theDatabase);
        }
        throw new DatabaseConnectionException("No connection found for the given database");
    }

    public DatabaseConnectionFactory setAndroidContext(Context theContext) {
        this.mContext = theContext;
        return this;
    }
}
